﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyKhachSan.BusinessLogic;
using QuanLyKhachSan.BusinessObject;
using QuanLyKhachSan.DataAccess;

namespace QuanLyKhachSan
{
    public partial class frmChucVu : Form
    {
        private ChucVuBL cvBL = new ChucVuBL();
        private ChucVuBO cvBO = new ChucVuBO();
        string chucvu = null;
        public frmChucVu()
        {
            InitializeComponent();
        }

        private void frmChucVu_Load(object sender, EventArgs e)
        {
            dgvwChucVu.DataSource = cvBL.LayChucVu();

        }

        //load dữ liệu lên textbox
        private void dgvwChucVu_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;
            cvBO.STT = int.Parse(dgvwChucVu.Rows[dong].Cells["STT"].Value.ToString());
            cvBO.MaChucVu = dgvwChucVu.Rows[dong].Cells["MaChucVu"].Value.ToString();
            cvBO.TenChucVu = dgvwChucVu.Rows[dong].Cells["TenChucVu"].Value.ToString();
            cvBO.TienLuong = int.Parse(dgvwChucVu.Rows[dong].Cells["TienLuong"].Value.ToString());
        }



        private void LayDuLieu(ChucVuBO CV)
        {
            this.chucvu = CV.MaChucVu;
            if (!chucvu.Equals(""))
            {
                dgvwChucVu.DataSource = cvBL.LayChucVu();
            }
        }



        private void txtTimKiem_KeyUp(object sender, KeyEventArgs e)
        {

        }

        private void btnThem_Click_1(object sender, EventArgs e)
        {
            frmAddChucVu facv = new frmAddChucVu();
            facv.NextID();
            facv.DuLieu = new frmAddChucVu.DuLieuTruyenVe(LayDuLieu);
            facv.Show();
        }

        private void btnSua_Click_1(object sender, EventArgs e)
        {
            frmAddChucVu facv = new frmAddChucVu();
            facv.Load_Edit(cvBO);
            facv.DuLieu = new frmAddChucVu.DuLieuTruyenVe(LayDuLieu);
            facv.Show();
        }

        private void btnXoa_Click_1(object sender, EventArgs e)
        {
            if (cvBO.MaChucVu == "")
                MessageBox.Show("Chọn mã nhân viên", "Chương trình thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa hay không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    cvBL.Delete(cvBO.MaChucVu);
                    frmChucVu_Load(sender, e);
                }
            }
        }

        private void toolStripButton4_Click_1(object sender, EventArgs e)
        {
            bool kq = (MessageBox.Show("Bạn có chắc chắn muốn thoát không ? ", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes);
            if (kq == true)
            {
                this.Close();
            }
        }

        private void txtTimKiem_KeyUp_1(object sender, KeyEventArgs e)
        {
            dgvwChucVu.DataSource = cvBL.TimKiemChucVu(txtTimKiem.Text);
        }




    }
}
